package fundamentals.unionfind;

import algUtils.StopWatch;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

public class App {
    public static void main(String[] args) {
        StopWatch timer=new StopWatch();
        int N = StdIn.readInt();
        //UnionQuickFind uf = new UnionQuickFind(N);
        //QuickUnionFind uf = new QuickUnionFind(N);
        WeightedQuickUnionFind uf = new WeightedQuickUnionFind(N);
        while (!StdIn.isEmpty()) {
            //读取整数对
            int p = StdIn.readInt();
            int q = StdIn.readInt();
            if (uf.connected(p, q)) continue;
            uf.union(p, q);
            StdOut.println(p + " " + q);

        }
        System.out.println("算法用时：" + timer.costTime() + "秒！");
    }
}